<!doctype html>



  


<html class="theme-next mist use-motion" lang="zh-Hans">
<head>
  <meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>



<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />















  
  
  <link href="/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css" />




  
  
  
  

  
    
    
  

  

  

  

  

  
    
    
    <link href="//fonts.googleapis.com/css?family=Lato:300,300italic,400,400italic,700,700italic&subset=latin,latin-ext" rel="stylesheet" type="text/css">
  






<link href="/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css" />

<link href="/css/main.css?v=5.1.0" rel="stylesheet" type="text/css" />


  <meta name="keywords" content="jvm,异常,字节码" />








  <link rel="shortcut icon" type="image/x-icon" href="/favicon.ico?v=5.1.0" />






<meta name="description" content="JVM 异常的本质 Java异常时java语言支持的唯一之中错误上报机制。  JVM异常体系异常的继承结构：Throwable为基类，Error和Exception继承Throwable，RuntimeException和IOException等继承Exception。Error和RuntimeException及其子类成为未检查异常（unchecked），其它异常成为已检查异常（checked）">
<meta name="keywords" content="jvm,异常,字节码">
<meta property="og:type" content="article">
<meta property="og:title" content="JVM异常体系及异常机制">
<meta property="og:url" content="http://www.zhizus.com/2018-07-07-JVM异常体系及异常机制.html">
<meta property="og:site_name" content="郑大侠的博客">
<meta property="og:description" content="JVM 异常的本质 Java异常时java语言支持的唯一之中错误上报机制。  JVM异常体系异常的继承结构：Throwable为基类，Error和Exception继承Throwable，RuntimeException和IOException等继承Exception。Error和RuntimeException及其子类成为未检查异常（unchecked），其它异常成为已检查异常（checked）">
<meta property="og:locale" content="zh-Hans">
<meta property="og:image" content="http://www.zhizus.com/images/ex-class-strut.jpg">
<meta property="og:image" content="http://www.zhizus.com/images/1530967496815.png">
<meta property="og:image" content="http://www.zhizus.com/images/1530967526425.png">
<meta property="og:updated_time" content="2018-07-30T00:44:48.230Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="JVM异常体系及异常机制">
<meta name="twitter:description" content="JVM 异常的本质 Java异常时java语言支持的唯一之中错误上报机制。  JVM异常体系异常的继承结构：Throwable为基类，Error和Exception继承Throwable，RuntimeException和IOException等继承Exception。Error和RuntimeException及其子类成为未检查异常（unchecked），其它异常成为已检查异常（checked）">
<meta name="twitter:image" content="http://www.zhizus.com/images/ex-class-strut.jpg">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Mist',
    sidebar: {"position":"left","display":"post"},
    fancybox: true,
    motion: true,
    duoshuo: {
      userId: '0',
      author: '博主'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: "",
      labels: ""
    }
  };
</script>



  <link rel="canonical" href="http://www.zhizus.com/2018-07-07-JVM异常体系及异常机制.html"/>





  <title> JVM异常体系及异常机制 | 郑大侠的博客 </title>
</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">

  





  <script type="text/javascript">
    var _hmt = _hmt || [];
    (function() {
      var hm = document.createElement("script");
      hm.src = "https://hm.baidu.com/hm.js?f75c9cec9ecead0dfce9a108b9688072";
      var s = document.getElementsByTagName("script")[0];
      s.parentNode.insertBefore(hm, s);
    })();
  </script>










  
  
    
  

  <div class="container sidebar-position-left page-post-detail ">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/"  class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">郑大侠的博客</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <p class="site-subtitle"></p>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br />
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/archives" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br />
            
            归档
          </a>
        </li>
      
        
        <li class="menu-item menu-item-categories">
          <a href="/categories" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-th"></i> <br />
            
            分类
          </a>
        </li>
      
        
        <li class="menu-item menu-item-crossed">
          <a href="http://zhizus.com" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-camera-retro"></i> <br />
            
            穿越
          </a>
        </li>
      
        
        <li class="menu-item menu-item-about">
          <a href="/about" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-user"></i> <br />
            
            关于
          </a>
        </li>
      

      
    </ul>
  

  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-java " itemscope itemtype="http://schema.org/Article">
    <link itemprop="mainEntityOfPage" href="http://www.zhizus.com/2018-07-07-JVM异常体系及异常机制.html">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="DempeZheng">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="https://avatars3.githubusercontent.com/u/6263631?v=3&s=466">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="郑大侠的博客">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
            
            
              
                JVM异常体系及异常机制
              
            
          </h1>
        

        <div class="post-meta">
          <span class="post-time">
            

            

            
          </span>

          

          
            
          

          
          
             <span id="/2018-07-07-JVM异常体系及异常机制.html" class="leancloud_visitors" data-flag-title="JVM异常体系及异常机制">
               <span class="post-meta-divider">|</span>
               <span class="post-meta-item-icon">
                 <i class="fa fa-eye"></i>
               </span>
               
                 <span class="leancloud-visitors-count"></span>
             </span>
          

          

          

          

        </div>
      </header>
    


    <div class="post-body" itemprop="articleBody">

      
      

      
        <h2 id="JVM-异常的本质"><a href="#JVM-异常的本质" class="headerlink" title="JVM 异常的本质"></a>JVM 异常的本质</h2><blockquote>
<p>Java异常时java语言支持的唯一之中<code>错误上报机制</code>。</p>
</blockquote>
<h2 id="JVM异常体系"><a href="#JVM异常体系" class="headerlink" title="JVM异常体系"></a>JVM异常体系</h2><p>异常的继承结构：Throwable为基类，Error和Exception继承Throwable，RuntimeException和IOException等继承Exception。Error和RuntimeException及其子类成为未检查异常（unchecked），其它异常成为已检查异常（checked）。</p>
<p><img src="./images/ex-class-strut.jpg" alt="Alt text"></p>
<h2 id="jvm异常原理"><a href="#jvm异常原理" class="headerlink" title="jvm异常原理"></a>jvm异常原理</h2><blockquote>
<p>JVM try catch原理你理解吗？
–据说是阿里巴巴的一道面试题</p>
</blockquote>
<h3 id="反编译一段小程序"><a href="#反编译一段小程序" class="headerlink" title="反编译一段小程序"></a>反编译一段小程序</h3><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title">main</span><span class="params">(String[] args)</span> </span>&#123;</span><br><span class="line">       <span class="keyword">int</span> a = <span class="number">1</span>;</span><br><span class="line">       <span class="keyword">int</span> b = <span class="number">3</span>;</span><br><span class="line">       <span class="keyword">try</span> &#123;</span><br><span class="line">           b = a + b;</span><br><span class="line">           <span class="keyword">return</span>;</span><br><span class="line">       &#125; <span class="keyword">catch</span> (RuntimeException e1) &#123;</span><br><span class="line">           b = a - b;</span><br><span class="line">       &#125; <span class="keyword">catch</span> (Exception e2) &#123;</span><br><span class="line">           b = a * b;</span><br><span class="line">       &#125; <span class="keyword">finally</span> &#123;</span><br><span class="line">           a = <span class="number">0</span>;</span><br><span class="line">       &#125;</span><br><span class="line">   &#125;</span><br></pre></td></tr></table></figure>
<p>通过命令javap -c Main 反编译.class文件得到一下输出：
<figure class="highlight avrasm"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br></pre></td><td class="code"><pre><span class="line">   <span class="number">0</span>: iconst_1</span><br><span class="line">   <span class="number">1</span>: istore_1 // 给局部变量表<span class="number">1</span>号slot赋值为<span class="number">1</span>，代表a</span><br><span class="line">   <span class="number">2</span>: iconst_3</span><br><span class="line">   <span class="number">3</span>: istore_2 // 给局部变量表<span class="number">2</span>号slot赋值为<span class="number">3</span>，代表b</span><br><span class="line">   <span class="number">4</span>: iload_1  // try块开始！</span><br><span class="line">   <span class="number">5</span>: iload_2</span><br><span class="line">   <span class="number">6</span>: iadd</span><br><span class="line">   <span class="number">7</span>: istore_2 // 指令<span class="number">4</span><span class="number">-7</span> 完成了操作：b = a + b</span><br><span class="line">   <span class="number">8</span>: iconst_0 // finally块开始！</span><br><span class="line">   <span class="number">9</span>: istore_1 // 指令<span class="number">8</span><span class="number">-9</span> 完成操作a=<span class="number">0</span></span><br><span class="line">  <span class="number">10</span>: return // 函数执行完毕，返回</span><br><span class="line">  <span class="number">11</span>: astore_3 // RuntimeException e1异常处理块开始！</span><br><span class="line">  <span class="number">12</span>: iload_1</span><br><span class="line">  <span class="number">13</span>: iload_2</span><br><span class="line">  <span class="number">14</span>: isub</span><br><span class="line">  <span class="number">15</span>: istore_2</span><br><span class="line">  <span class="number">16</span>: iconst_0 // finally处理块</span><br><span class="line">  <span class="number">17</span>: istore_1</span><br><span class="line">  <span class="number">18</span>: goto          <span class="number">38</span> // RuntimeException e1异常处理块结束！</span><br><span class="line">  <span class="number">21</span>: astore_3 // Exception e2异常处理块开始！</span><br><span class="line">  <span class="number">22</span>: iload_1</span><br><span class="line">  <span class="number">23</span>: iload_2</span><br><span class="line">  <span class="number">24</span>: imul</span><br><span class="line">  <span class="number">25</span>: istore_2</span><br><span class="line">  <span class="number">26</span>: iconst_0 // finally处理块</span><br><span class="line">  <span class="number">27</span>: istore_1</span><br><span class="line">  <span class="number">28</span>: goto          <span class="number">38</span> // Exception e2 异常处理块结束！</span><br><span class="line">  <span class="number">31</span>: astore        <span class="number">4</span> // 其他任何异常处理块</span><br><span class="line">  <span class="number">33</span>: iconst_0</span><br><span class="line">  <span class="number">34</span>: istore_1</span><br><span class="line">  <span class="number">35</span>: aload         <span class="number">4</span></span><br><span class="line">  <span class="number">37</span>: athrow // 往将异常外抛</span><br><span class="line">  <span class="number">38</span>: return</span><br><span class="line">Exception table: // 异常表</span><br><span class="line">   from    to  target type</span><br><span class="line">       <span class="number">4</span>     <span class="number">8</span>    <span class="number">11</span>   Class java/lang/RuntimeException //<span class="number">4</span><span class="number">-8</span> 号指令中，碰到 NullPointerException时，跳到 <span class="number">11</span> 号指令</span><br><span class="line">       <span class="number">4</span>     <span class="number">8</span>    <span class="number">21</span>   Class java/lang/Exception</span><br><span class="line">       <span class="number">4</span>     <span class="number">8</span>    <span class="number">31</span>   any</span><br><span class="line">      <span class="number">11</span>    <span class="number">16</span>    <span class="number">31</span>   any</span><br><span class="line">      <span class="number">21</span>    <span class="number">26</span>    <span class="number">31</span>   any</span><br><span class="line">      <span class="number">31</span>    <span class="number">33</span>    <span class="number">31</span>   any</span><br></pre></td></tr></table></figure></p>
<h3 id="异常表"><a href="#异常表" class="headerlink" title="异常表"></a>异常表</h3><p>异常表的每个入口信息包括：</p>
<ul>
<li>1起点</li>
<li>2终点</li>
<li>3将要跳转到的字节码序列的pc指针偏移量</li>
<li>4被捕获异常类的常量池索引</li>
</ul>
<p>异常表实际上记录了try catch的关键逻辑。
try的起点，和try的终点，以及catch的起点（及时将要跳转的位置）</p>
<p>另外，我们从反编译的字节码可以看到，异常表与字节码序列一起存到class 文件中。</p>
<p>jvm的异常处理的逻辑：</p>
<ul>
<li>1.如果发生异常，jvm在表中查找异常，如果找到异常，就跳转到实现catch字句的字节码序列。</li>
<li>2.如果没有发现相匹配的项，jvm将当前栈帧从栈中弹出，再次抛出同样的异常。</li>
<li>3.当jvm弹出当前栈帧时，jvm马上终止当前方法的执行，并且返回到调用本方法</li>
<li><ol start="4">
<li>但是并非继续正常执行该方法，而是在该方法中抛出同样的异常，使得jvm在该方法中再次执行同样的搜索异常表的操作。</li>
</ol>
</li>
</ul>
<h2 id="异常的开销"><a href="#异常的开销" class="headerlink" title="异常的开销"></a>异常的开销</h2><p>首先异常是有开销的，也就是使用异常是有成本的。这点基本上是共识。
现在的问题是异常的开销究竟有多大?
要搞清楚这个问题，就要弄明白异常的消耗主要来自哪里？</p>
<p>1、当代码出现异常的时候，首先需要创建一个异常
2、创建一个异常时，需要收集一个栈用来跟踪异常情况
3、栈跟踪异常情况需要记录下来（入栈，出栈），一直跟踪到我们扑捉到异常并且进行处理后截止</p>
<blockquote>
<p>根本原因在于:
异常基类Throwable.java的public synchronized native Throwable fillInStackTrace()方法
方法介绍:
Fills in the execution stack trace. This method records within this Throwable object information about the current state of the stack frames for the current thread.
性能开销在于:
<strong>1. 是一个<code>synchronized</code>方法(主因)</strong>
<strong>2. 需要填充线程运行堆栈信息</strong></p>
</blockquote>
<h2 id="异常控制流程的一些争论"><a href="#异常控制流程的一些争论" class="headerlink" title="异常控制流程的一些争论"></a>异常控制流程的一些争论</h2><p>关于要不要以来异常机制来处理控制流程，一直以来就有这个争论。不少帖子都讨论过这个问题。
在两本不同的书里面也见到了截然不同的观点：</p>
<ul>
<li>effect Java不建议用异常来控制业务流程，理由是异常消耗比较大。</li>
<li>代码简洁之道则是相反，建议用异常来处理业务控制流程，减少不必要的return</li>
</ul>
<p>这个是一个取舍问题，关键点在你想要什么，如果对性能没有极致追求，其实用异常来控制业务流程也不错，清晰直观。</p>
<h2 id="补充"><a href="#补充" class="headerlink" title="补充"></a>补充</h2><h3 id="try-catch-finally-return执行顺序"><a href="#try-catch-finally-return执行顺序" class="headerlink" title="try catch finally return执行顺序"></a>try catch finally return执行顺序</h3><p>这里有一个常见的面试题，就是return 和finally的执行顺序问题，
从java语言的角度理解很诡异，但是从指令就比较容易理解。
结论：finally的代码执行是在最后一条return指令之前。</p>
<h3 id="idea-字节码工具插件jclasslib"><a href="#idea-字节码工具插件jclasslib" class="headerlink" title="idea 字节码工具插件jclasslib"></a>idea 字节码工具插件jclasslib</h3><p>在了解异常原理的过程中发现了一个很不错的查看修改字节码的 idea插件 <code>jclasslib</code> 。
<a href="https://github.com/ingokegel/jclasslib" target="_blank" rel="noopener">https://github.com/ingokegel/jclasslib</a>
用它来查看字节码是这样的。
<img src="./images/1530967496815.png" alt="Alt text">
<img src="./images/1530967526425.png" alt="Alt text"></p>
<h2 id="参考文章"><a href="#参考文章" class="headerlink" title="参考文章"></a>参考文章</h2><p><a href="https://blog.csdn.net/TellH/article/details/70940757" target="_blank" rel="noopener">https://blog.csdn.net/TellH/article/details/70940757</a><br><a href="http://icyfenix.iteye.com/blog/857722" target="_blank" rel="noopener">http://icyfenix.iteye.com/blog/857722</a></p>

      
    </div>

    <div>
      
        

      
    </div>

    <div>
      
        
  <div style="padding: 10px 0; margin: 20px auto; width: 90%; text-align: center;">
    <div>大侠劫富济贫啦！</div>
    <button id="rewardButton" disable="enable" onclick="var qr = document.getElementById('QR'); if (qr.style.display === 'none') {qr.style.display='block';} else {qr.style.display='none'}">
      <span>赏</span>
    </button>
    <div id="QR" style="display: none;">
      
        <div id="wechat" style="display: inline-block">
          <img id="wechat_qr" src="/images/dempe/20180527112524.jpg" alt="DempeZheng WeChat Pay"/>
        </div>
      
      
    </div>
  </div>


      
    </div>

    <div>
      
        

      
    </div>

    <footer class="post-footer">
      

      
        
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/2018-07-07-如何快速提高代码测试覆盖率.html" rel="next" title="如何快速提高测试代码覆盖率">
                <i class="fa fa-chevron-left"></i> 如何快速提高测试代码覆盖率
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/2018-07-11-Java DNS cache.html" rel="prev" title="Java DNS Cache小记">
                Java DNS Cache小记 <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          


          
  <div class="comments" id="comments">
    
      <div id="SOHUCS"></div>
    
  </div>


        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap" >
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview">
            站点概览
          </li>
        </ul>
      

      <section class="site-overview sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
          <img class="site-author-image" itemprop="image"
               src="https://avatars3.githubusercontent.com/u/6263631?v=3&s=466"
               alt="DempeZheng" />
          <p class="site-author-name" itemprop="name">DempeZheng</p>
           
              <p class="site-description motion-element" itemprop="description">請更固執，將自己謀生與擅長的事情做到最好</p>
          
        </div>
        <nav class="site-state motion-element">

          
            <div class="site-state-item site-state-posts">
              <a href="/archives">
                <span class="site-state-item-count">68</span>
                <span class="site-state-item-name">日志</span>
              </a>
            </div>
          

          
            
            
            <div class="site-state-item site-state-categories">
              <a href="/categories/index.html">
                <span class="site-state-item-count">23</span>
                <span class="site-state-item-name">分类</span>
              </a>
            </div>
          

          

        </nav>

        

        <div class="links-of-author motion-element">
          
            
              <span class="links-of-author-item">
                <a href="https://github.com/dempeZheng" target="_blank" title="GitHub">
                  
                    <i class="fa fa-fw fa-github"></i>
                  
                  GitHub
                </a>
              </span>
            
              <span class="links-of-author-item">
                <a href="http://music.163.com/#/user/home?id=6758793" target="_blank" title="网易云音乐">
                  
                    <i class="fa fa-fw fa-globe"></i>
                  
                  网易云音乐
                </a>
              </span>
            
              <span class="links-of-author-item">
                <a href="https://www.zhihu.com/people/dempe" target="_blank" title="知乎">
                  
                    <i class="fa fa-fw fa-globe"></i>
                  
                  知乎
                </a>
              </span>
            
          
        </div>

        
        

        
        
          <div class="links-of-blogroll motion-element links-of-blogroll-inline">
            <div class="links-of-blogroll-title">
              <i class="fa  fa-fw fa-globe"></i>
              Links
            </div>
            <ul class="links-of-blogroll-list">
              
                <li class="links-of-blogroll-item">
                  <a href="http://www.wolfbe.com/" title="朗度云" target="_blank">朗度云</a>
                </li>
              
            </ul>
          </div>
        

        


      </section>

      
      <!--noindex-->
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
              
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#JVM-异常的本质"><span class="nav-number">1.</span> <span class="nav-text">JVM 异常的本质</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#JVM异常体系"><span class="nav-number">2.</span> <span class="nav-text">JVM异常体系</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#jvm异常原理"><span class="nav-number">3.</span> <span class="nav-text">jvm异常原理</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#反编译一段小程序"><span class="nav-number">3.1.</span> <span class="nav-text">反编译一段小程序</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#异常表"><span class="nav-number">3.2.</span> <span class="nav-text">异常表</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#异常的开销"><span class="nav-number">4.</span> <span class="nav-text">异常的开销</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#异常控制流程的一些争论"><span class="nav-number">5.</span> <span class="nav-text">异常控制流程的一些争论</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#补充"><span class="nav-number">6.</span> <span class="nav-text">补充</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#try-catch-finally-return执行顺序"><span class="nav-number">6.1.</span> <span class="nav-text">try catch finally return执行顺序</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#idea-字节码工具插件jclasslib"><span class="nav-number">6.2.</span> <span class="nav-text">idea 字节码工具插件jclasslib</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#参考文章"><span class="nav-number">7.</span> <span class="nav-text">参考文章</span></a></li></ol></div>
            

          </div>
        </section>
      <!--/noindex-->
      

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright" >
  
  &copy; 
  <span itemprop="copyrightYear">2018</span>
  <span class="with-love">
    <i class="fa fa-"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">DempeZheng</span>
</div>



        

        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
      </div>
    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  






  
  <script type="text/javascript" src="/lib/jquery/index.js?v=2.1.3"></script>

  
  <script type="text/javascript" src="/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>

  
  <script type="text/javascript" src="/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>

  
  <script type="text/javascript" src="/lib/velocity/velocity.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>


  


  <script type="text/javascript" src="/js/src/utils.js?v=5.1.0"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=5.1.0"></script>



  
  

  
  <script type="text/javascript" src="/js/src/scrollspy.js?v=5.1.0"></script>
<script type="text/javascript" src="/js/src/post-details.js?v=5.1.0"></script>



  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=5.1.0"></script>



  


  




	





  





  





  






  





  

  
  <script src="https://cdn1.lncld.net/static/js/av-core-mini-0.6.1.js"></script>
  <script>AV.initialize("dhzMp0HdJLWMCrt04bwybWzH-gzGzoHsz", "gH6FmxJiUaVLLRXQDWpkkIVv");</script>
  <script>
    function showTime(Counter) {
      var query = new AV.Query(Counter);
      var entries = [];
      var $visitors = $(".leancloud_visitors");

      $visitors.each(function () {
        entries.push( $(this).attr("id").trim() );
      });

      query.containedIn('url', entries);
      query.find()
        .done(function (results) {
          var COUNT_CONTAINER_REF = '.leancloud-visitors-count';

          if (results.length === 0) {
            $visitors.find(COUNT_CONTAINER_REF).text(0);
            return;
          }

          for (var i = 0; i < results.length; i++) {
            var item = results[i];
            var url = item.get('url');
            var time = item.get('time');
            var element = document.getElementById(url);

            $(element).find(COUNT_CONTAINER_REF).text(time);
          }
          for(var i = 0; i < entries.length; i++) {
            var url = entries[i];
            var element = document.getElementById(url);
            var countSpan = $(element).find(COUNT_CONTAINER_REF);
            if( countSpan.text() == '') {
              countSpan.text(0);
            }
          }
        })
        .fail(function (object, error) {
          console.log("Error: " + error.code + " " + error.message);
        });
    }

    function addCount(Counter) {
      var $visitors = $(".leancloud_visitors");
      var url = $visitors.attr('id').trim();
      var title = $visitors.attr('data-flag-title').trim();
      var query = new AV.Query(Counter);

      query.equalTo("url", url);
      query.find({
        success: function(results) {
          if (results.length > 0) {
            var counter = results[0];
            counter.fetchWhenSave(true);
            counter.increment("time");
            counter.save(null, {
              success: function(counter) {
                var $element = $(document.getElementById(url));
                $element.find('.leancloud-visitors-count').text(counter.get('time'));
              },
              error: function(counter, error) {
                console.log('Failed to save Visitor num, with error message: ' + error.message);
              }
            });
          } else {
            var newcounter = new Counter();
            /* Set ACL */
            var acl = new AV.ACL();
            acl.setPublicReadAccess(true);
            acl.setPublicWriteAccess(true);
            newcounter.setACL(acl);
            /* End Set ACL */
            newcounter.set("title", title);
            newcounter.set("url", url);
            newcounter.set("time", 1);
            newcounter.save(null, {
              success: function(newcounter) {
                var $element = $(document.getElementById(url));
                $element.find('.leancloud-visitors-count').text(newcounter.get('time'));
              },
              error: function(newcounter, error) {
                console.log('Failed to create');
              }
            });
          }
        },
        error: function(error) {
          console.log('Error:' + error.code + " " + error.message);
        }
      });
    }

    $(function() {
      var Counter = AV.Object.extend("Counter");
      if ($('.leancloud_visitors').length == 1) {
        addCount(Counter);
      } else if ($('.post-title-link').length > 1) {
        showTime(Counter);
      }
    });
  </script>



  

  

  

</body>
</html>
